/**
  * Defines a set of internal functions to be used when implementing
  * the functions prototyped in lcd.h.
  *
  * @author t a y l o r@msoe.edu
  * @version 2008.03.13
  */

#ifndef _LCDPRIVATE_H
#define _LCDPRIVATE_H

#define LCD_CTRL_RS		2
#define LCD_CTRL_RD		3
#define LCD_CTRL_WR		1
#define LCD_CTRL_E		0
#define LCD_LINE_OFFSET	0x40	// Offset required to get to second line of LCD

/** lcd_port Global variable representing the port used by the LCD. */
static char lcd_port = 'C';

/**
  * Send one byte of data to the LCD panel.
  *
  * @param data The data value to be sent to the LCD panel.
  */
void lcd_data_write(uint8_t data);

/**
  * Send a one byte command to the LCD panel.
  *
  * @param cmd The command to be sent to the LCD panel.
  */
void lcd_cmd_write(uint8_t cmd);

/**
  * Write one byte (cmd or data) to the LCD panel.
  *
  * @param value The command/data to be sent to the LCD panel.
  * @param is_data non-zero if writing data, zero if writing a command.
  */
void lcd_write(uint8_t value, _Bool is_data);

/**
  * Write one nibble to the LCD panel.  The nibble to be written should
  * be in the lower half of the byte passed.
  *
  * @param value The nibble (in the lower four bits) to be sent to the LCD panel.
  * @param is_data non-zero if writing data, zero if writing a command.
  */
void lcd_write_nibble(uint8_t data, _Bool is_data);

/**
  * Sends data to the port to which the LCD is attached.
  * If lcd_port contains a corrupt value, the default port (PORTC) will be used.
  *
  * @param data The value to be written to the port.
  */
void write_lcd_port(uint8_t data);

/**
  * Sends data to DDR for the to which the LCD is attached.
  * If lcd_port contains a corrupt value, the default port (PORTC) will be used.
  *
  * @param value The value to be written to the port.
  */
void write_lcd_ddr(uint8_t data);

/**
  * Sets a bit in the port to which the LCD is attached.
  * If lcd_port contains a corrupt value, the default port (PORTC) will be used.
  *
  * @param bit The bit (0-7) to be set in the port.
  */
void lcd_sbi(uint8_t bit);

/**
  * Clears a bit in the port to which the LCD is attached.
  * If lcd_port contains a corrupt value, the default port (PORTC) will be used.
  *
  * @param bit The bit (0-7) to be cleared in the port.
  */
void lcd_cbi(uint8_t bit);

#endif
